# encoding = utf-8
# @file include.py
# Create 05/11/2011 legs.ant.king@gmail.com
INNODB_PAGE_SIZE = 1024*16 # InnoDB Page 16K
######################################################################### 
# 		 	define page fil head offset			# 
######################################################################### 
# * File space address on page number within a space and byte offset within the page *
# < in < MySQL-4.0.14 space id the page belongs to ( ==  0) but in later versions the 'new' checksum of the  page 
FIL_PAGE_SPACE_OR_CHKSUM = 0
# < page offset inside space 
FIL_PAGE_OFFSET = 4
# < if there is a 'natural' predecessor of the page, its offset.  Otherwise FIL_NULL. This field is not set on BLOB pages, which are stored as a singly-linked list.  See also FIL_PAGE_NEXT. 
FIL_PAGE_PREV = 8
# < if there is a 'natural' successor of the page, its offset. Otherwise FIL_NULL. B-tree index pages (FIL_PAGE_TYPE contains FIL_PAGE_INDEX on the same PAGE_LEVEL are maintained as a doubly linked list via FIL_PAGE_PREV and FIL_PAGE_NEXT in the collation order of the smallest user record on each page. 
#  Note FIL_PAGE_PREV + FIL_PAGE_NEXT = double linked list table fetch all list table for page
FIL_PAGE_NEXT = 12
# < lsn of the end of the newest modification log record to the page 
FIL_PAGE_LSN = 16
# < file page type: FIL_PAGE_INDEX,.. 2 bytes. The contents of this field can only be trusted in the following case: if the page is an uncompressed B-tree index page, then it is guaranteed that the value is FIL_PAGE_INDEX. The opposite does not hold. In tablespaces created by MySQL/InnoDB 5.1.7 or later, the  contents of this field is valid for all uncompressed pages. 
#  note detail page type on dic innodb_page_type
FIL_PAGE_TYPE = 24
# < this is only defined for the first page in a system tablespace data file (ibdata*, not *.ibd): the file has been flushed to disk at least up to this lsn 
FIL_PAGE_FILE_FLUSH_LSN = 26
# < starting from 4.1.x this contains the space id of the page 
FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID = 34
# < start of the data on the page 
FIL_PAGE_DATA = 38
# < the low 4 bytes of this are used to store the page checksum, the last 4 bytes should be identical to the last 4 bytes of FIL_PAGE_LSN 
# File header count 38 byte
FIL_TABLESPACE = 501 # < tablespace 
FIL_LOG = 502 # < redo log 
######################################################################### 
# 		 	define innodb page offset			# 
######################################################################### 
PAGE_N_DIR_SLOTS = FIL_PAGE_DATA # number of slots in page directory
PAGE_N_HEAP = FIL_PAGE_DATA + 4 # pointer to record heap top
PAGE_N_RECS = FIL_PAGE_DATA + 16 # number of user records on the page 
PAGE_LEVEL = FIL_PAGE_DATA + 26 # level of the node in an index tree the leaf level is the level 0.  This field should not be written to after page creation.
PAGE_INDEX_ID = FIL_PAGE_DATA + 28
# Types of an undo log segment specified free records page pointer for 2 bit
PAGE_FREE = FIL_PAGE_DATA + 6
# specifed deleted records pointer for 2 bit
PAGE_GARBAGE = FIL_PAGE_DATA + 8
TRX_UNDO_INSERT = 1
TRX_UNDO_UPDATE = 2
# On a page of any file segment, data may be put starting from this offset
FSEG_PAGE_DATA = FIL_PAGE_DATA
# The offset of the undo log page header on pages of the undo log
TRX_UNDO_PAGE_HDR = FSEG_PAGE_DATA
# page data PAGE_HEADER + 36 + 2 * FSEG_HEADER_SIZE  ===  38 + 36 + 2*10 = 38 + 56 = 94
PAGE_DATA = 94
REC_N_NEW_EXTRA_BYTES = PAGE_DATA
# B- Root PAGE_BTR_SEG_TOP 36 + 38
PAGE_BTR_SEG_TOP = 74
# PAGE_DATA + REC_N_NEW_EXTRA_BYTES*2 + 8
PAGE_NEW_SUPREMUM = 117
PAGE_NEW_SUPREMUM_END = 125
# PAGE_DATA + REC_N_NEW_EXTRA_BYTES = 94 + 5
PAGE_NEW_INFIMUM = 99
# PAGE_DATA + 1 + REC_N_OLD_EXTRA_BYTES = 94 + 1 + 6
PAGE_OLD_INFIMUM = 101
# PAGE_OLD_SUPREMUM	(PAGE_DATA + 2 + 2 * REC_N_OLD_EXTRA_BYTES + 8) = 94 + 2 + 12 + 8  ==  22 + 94  ==  116
PAGE_OLD_SUPREMUM = 116
# PAGE_OLD_SUPREMUM_END (PAGE_OLD_SUPREMUM + 9) = 116 + 9 = 225
PAGE_OLD_SUPREMUM_END = 225
# PAGE_EMPTY_DIR_START PAGE_DIR( == trailer = 8) + 2*PAGE_DIR_SLOT_SIZE = 8 + 4 = 12 Reserved 2 byte slot dir in slot and trailer
PAGE_EMPTY_DIR_START = 12
FIRST_DIR_INFIMUN = INNODB_PAGE_SIZE - 8 # TRILER

######################################################################### 
# 		 	define innodb page type				# 
######################################################################### 
innodb_page_type = {
	'0000':u'Freshly Allocated Page',
	'0002':u'Undo Log Page',
	'0003':u'File Segment inode',
	'0004':u'Insert Buffer Free List',
	'0005':u'Insert Buffer Bitmap',
	'0006':u'System Page',
	'0007':u'Transaction system Page',
	'0008':u'File Space Header',
	'0009':u'Extented Description Page',
	'000a':u'Uncompressed BLOB Page',
	'000b':u'1st compressed BLOB Page',
	'000c':u'Subsequent compressed BLOB Page',
	'45bf':u'B-tree Node'
	}
innodb_page_direction = {
	'0000': 'Unknown(0x0000)',
	'0001': 'Page Left',
	'0002': 'Page Right',
	'0003': 'Page Same Rec',
	'0004': 'Page Same Page',
	'0005': 'Page No Direction',
	'ffff': 'Unkown2(0xffff)'
}
dif = {
	# fil subdef
	  'FIL_PAGE_SPACE_OR_CHKSUM':4
	, 'FIL_PAGE_OFFSET':4
	, 'FIL_PAGE_PREV':4
	, 'FIL_PAGE_NEXT':4
	, 'FIL_PAGE_LSN':8
	, 'FIL_PAGE_TYPE':2
	, 'FIL_PAGE_FILE_FLUSH_LSN':8
	, 'FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID':4
	# page subdef
	, 'PAGE_N_DIR_SLOTS':2
	, 'PAGE_N_HEAP':2
	, 'PAGE_N_RECS':2
	, 'PAGE_LEVEL':2
	, 'PAGE_FREE':2
	, 'PAGE_GARBAGE':2
	, 'PAGE_INDEX_ID':8
	, 'REC_N_NEW_EXTRA_BYTES':5
	, 'INFIMUN_POS':2
}
